<template>
  <div>
    <div class="bg"></div>
    <div class="animation">
      <div><span class="span0" :class="[isShow[0] ? '' : 'is-show']"></span></div>
      <div><span class="span1" :class="[isShow[1] ? '' : 'is-show']"></span></div>
      <div><span class="span2" :class="[isShow[2] ? '' : 'is-show']"></span></div>
      <div><span class="span3" :class="[isShow[3] ? '' : 'is-show']"></span></div>
      <div><span class="span4" :class="[isShow[4] ? '' : 'is-show']"></span></div>
    </div>
  </div>
</template>

<script>
let timer = null;
export default {
  props: {
    isLoading: Boolean
  },
  data () {
    return {
      isShow: [false, false, false, false, false]
    }
  },
  created () {
    this.setShowBox();
  },
  mounted () {},
  adtivated () {
    this.setShowBox();
  },
  methods: {
    setShowBox () {
      timer = setInterval(() => {
        if (this.isLoading) clearInterval(timer)
        let allShow = this.isShow.every((item) => {
          return item;
        });
        if (allShow) {
          this.isShow = [false, false, false, false, false]
        } else {
          for (let i = 4; i >= 0; i--) {
            if (!this.isShow[i]) {
              this.isShow.splice(i, 1, true);
              break;
            }
          }
        }
      }, 300);
    }
  }
}
</script>

<style lang="less">
  .bg {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background-color: rgba(0, 0, 0, .7)
  }
  .animation {
    position: fixed;
    top: 50%;
    left: 50%;
    color: white;
    margin: -60px 0 0 -30px;
    text-align: center;
    .is-show {
      visibility: hidden;
    }
    span {
      display: inline-block;
      width: 60px;
      height: 10px;
      background-color: blue;
    }
    .span0, .span4 {
      width: 20px;
      height: 10px;
      background-color: white;
    }
    .span1, .span3 {
      width: 40px;
      height: 10px;
      background-color: red;
    }
  }
</style>

